<template>
  <div class="box">
    <div class="carousel">
      <button @click="prevSlide" class="prev-button">&lt;</button>
      <div class="slides">
        <img v-for="(image, index) in images" :key="index" :src="image" :class="{ 'active': currentIndex === index }">
      </div>
      <button @click="nextSlide" class="next-button">&gt;</button>
      <div class="indicators">
<!--        <span v-for="(_, index) in images" :key="index" :class="{ 'active': currentIndex === index }" @click="goToSlide(index)"></span>-->
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "Index",
  data() {
    return {
      // 版本号
      version: "3.8.8",
      images: [
        require('../assets/images/banners/banner1.png'),
        require('../assets/images/banners/banner2.gif'),
        require('../assets/images/banners/banner3.png'),
        require('../assets/images/banners/banner4.gif')
      ],
      currentIndex: 0
    };
  },
  mounted() {
    this.startAutoSlide();
  },
  methods: {
    goTarget(href) {
      window.open(href, "_blank");

    },
    startAutoSlide() {
      this.timer = setInterval(() => {
        this.nextSlide();
      }, 3000);
    },
    prevSlide() {
      this.currentIndex = (this.currentIndex - 1 + this.images.length) % this.images.length;
    },
    nextSlide() {
      this.currentIndex = (this.currentIndex + 1) % this.images.length;
    },
  }
};
</script>

<style scoped lang="scss">
.box{
  width: 100%;
  height: 100%;
}
.carousel {
  width: 100%;
  position: relative;
}
.prev-button,
.next-button {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  font-size: 24px;
  background-color: rgba(0, 0, 0, 0.3);
  color: white;
  border: none;
  padding: 10px 15px;
  cursor: pointer;
}

.prev-button {
  left: 10px;
}

.next-button {
  right: 10px;
}

.slides {
  width: 100%;
  overflow: hidden;
}

.slides img {
  width: 100%;
  display: none;
}

.slides img.active {
  display: block;
}

.indicators {
  text-align: center;
  margin-top: 10px;
}

.indicators span {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background-color: gray;
  margin: 0 5px;
  cursor: pointer;
}

.indicators span.active {
  background-color: black;
}
</style>


